package com.kzd.sdk.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.kzd.sdk.base.OwnerActivity;
import com.kzd.sdk.callback.KZD_HttpCallback;
import com.kzd.sdk.callback.KZD_OnItemClickListener;
import com.kzd.sdk.core.KZD_ApiManager;
import com.kzd.sdk.entity.KZD_GameRebate;
import com.kzd.sdk.ui.adapter.KZD_GameRebateAdapter;
import com.kzd.sdk.utils.AppUtils;

import java.util.List;

public class KZD_RebateRecordActivity extends OwnerActivity {

    public static void open(Context context) {
        Intent intent = new Intent(context, KZD_RebateRecordActivity.class);
        context.startActivity(intent);
    }

    private RecyclerView mRecyclerView;
    private SwipeRefreshLayout mSwipeRefreshLayout;

    private KZD_GameRebateAdapter mGameRebateAdapter;

    private KZD_HttpCallback<List<KZD_GameRebate.List>> callbackGameRebate = new KZD_HttpCallback<List<KZD_GameRebate.List>>() {
        @Override
        public void onSuccess(List<KZD_GameRebate.List> data) {
            mGameRebateAdapter.setNewInstance(data);
            mSwipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onError(String error) {
            toast(error);
            mSwipeRefreshLayout.setRefreshing(false);
        }
    };

    @Override
    public String getLayoutIdByName() {
        return "kzd_activity_rebate_record";
    }

    @Override
    public View getLayoutView() {
        return null;
    }

    @Override
    public void initView() {


        findViewById(AppUtils.getId((this), "ivBackPressed"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onBackPressed();
                    }
                });

        findViewById(AppUtils.getId((this), "ivRebateRecordService"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        KZD_UserServiceActivity.open((KZD_RebateRecordActivity.this));
                    }
                });

        mRecyclerView = findViewById(AppUtils.getId((this), "mRecyclerView"));
        mGameRebateAdapter = new KZD_GameRebateAdapter((this));
        mGameRebateAdapter.setOnItemClickListener(new KZD_OnItemClickListener() {
            @Override
            public void onClick(View v, int position) {

            }
        });
        mRecyclerView.setLayoutManager(new LinearLayoutManager((this)));
        mRecyclerView.setAdapter(mGameRebateAdapter);

        mSwipeRefreshLayout = findViewById(AppUtils.getId((this), "mSwipeRefreshLayout"));
        mSwipeRefreshLayout.setColorSchemeResources(AppUtils.getColorId((this), "kzd_2983ff"));
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                initData();
            }
        });

    }

    @Override
    public void initData() {
        KZD_ApiManager.httpRebateApplyRecord(callbackGameRebate);
    }
}
